import { BusinessType, MessageType } from "@/enums/sysEnum";
import { useUserStore } from "@/stores/modules/user";
import httpRequest from "@/api/services";
import { reactive } from "vue";
import { Message } from "@/api/types/base";
import sysUrl from "@/api/services/sysUrl";
import { generateUUID } from "@/utils";
export const useMessage = (businessType: string = BusinessType.SYS) => {
  const userInfo = useUserStore().userInfo;

  const state = reactive({
    tableName: "message"
  });

  const sendSysMessage = async (businessId: string, title: string, summary: string, type: MessageType, toUsers: string[]) => {
    const message: Message = {
      messageId: generateUUID(),
      businessId: businessId,
      businessType: businessType,
      title: title,
      toUsers: toUsers,
      summary: summary,
      type: type,
      create_user: userInfo._id,
      create_at: new Date()
    };
    return httpRequest.post(sysUrl.BASE_SAVE + state.tableName, message);
  };

  return {
    sendSysMessage
  };
};
